/**
 *  Copyright 2011 Marco Berri - marcoberri@gmail.com
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License.
 **/
package com.mbfasttrack.model;

import java.io.File;
import java.util.Date;
import java.util.ArrayList;
import java.util.List;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

/**
 * @author Marco Berri marcoberri@gmail.com http://tecnicume.blogspot.com
 */
@Document
public class Track implements Base {

    @Id
    @Indexed
    private String id;
    @Indexed(unique = true)
    private String slug;
    private String name;
    private String description;
    private Object fileId;
    private Date date;
    private Date datestart;
    private Date datestop;
    private Date dateSaved = new Date(System.currentTimeMillis());
    private String kmlDescription;
    private Double maxAltitude;
    private Double minAltitude;
    private Double minLat;
    private Double maxLat;
    private Double minLon;
    private Double maxLon;
    private Double distance;
    private Double elevation;
    private Double realelevation;
    @Indexed
    private String activity;
    @Transient
    private String hardware;
    @DBRef
    private Hardware hardwareLink;
    private Boolean publicview;
    private Point startpoint;
    private CommonsMultipartFile file;
    private File fileImported;
    @DBRef
    private List<Tag> tagsLink = new ArrayList();
    @DBRef
    private List<Media> media = new ArrayList();
    @DBRef
    private User user;
    @DBRef
    private TrackPoint trackpoint;
    @Transient
    private String tags;

    /**
     * 
     */
    public Track() {
    }

    /**
     * 
     * @return
     */
    @Override
    public String toString() {
        return "Track [id=" + getId() + " description=" + getDescription() + " maxAltitude:" + getMaxAltitude() + " minAltitude:" + getMinAltitude() + "]";
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * @return the user
     */
    public User getUser() {
        return user;
    }

    /**
     * @param user the user to set
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * @return the file
     */
    public CommonsMultipartFile getFile() {
        return file;
    }

    /**
     * @param file the file to set
     */
    public void setFile(CommonsMultipartFile file) {
        this.file = file;
    }

    /**
     * @return the fileId
     */
    public Object getFileId() {
        return fileId;
    }

    /**
     * @param fileId the fileId to set
     */
    public void setFileId(Object fileId) {
        this.fileId = fileId;
    }

    /**
     * @return the date
     */
    public Date getDate() {
        return date;
    }

    /**
     * @param date the date to set
     */
    public void setDate(Date date) {
        this.date = date;
    }

    /**
     * @return the kmlDescription
     */
    public String getKmlDescription() {
        return kmlDescription;
    }

    /**
     * @param kmlDescription the kmlDescription to set
     */
    public void setKmlDescription(String kmlDescription) {
        this.kmlDescription = kmlDescription;
    }

    /**
     * @return the kmlMaxAltitude
     */
    public Double getMaxAltitude() {
        return maxAltitude;
    }

    /**
     * @param maxAltitude 
     */
    public void setMaxAltitude(Double maxAltitude) {
        this.maxAltitude = maxAltitude;
    }

    /**
     * @return the kmlMinAltitude
     */
    public Double getMinAltitude() {
        return minAltitude;
    }

    /**
     * @param minAltitude 
     */
    public void setMinAltitude(Double minAltitude) {
        this.minAltitude = minAltitude;
    }

    /**
     * @return the id
     */
    public String getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * @return the maxLat
     */
    public Double getMaxLat() {
        return maxLat;
    }

    /**
     * @param maxLat the maxLat to set
     */
    public void setMaxLat(Double maxLat) {
        this.maxLat = maxLat;
    }

    /**
     * @return the minLon
     */
    public Double getMinLon() {
        return minLon;
    }

    /**
     * @param minLon the minLon to set
     */
    public void setMinLon(Double minLon) {
        this.minLon = minLon;
    }

    /**
     * @return the maxLon
     */
    public Double getMaxLon() {
        return maxLon;
    }

    /**
     * @param maxLon the maxLon to set
     */
    public void setMaxLon(Double maxLon) {
        this.maxLon = maxLon;
    }

    /**
     * @return the minLat
     */
    public Double getMinLat() {
        return minLat;
    }

    /**
     * @param minLat the minLat to set
     */
    public void setMinLat(Double minLat) {
        this.minLat = minLat;
    }

    /**
     * @return the slug
     */
    public String getSlug() {
        return slug;
    }

    /**
     * @param slug the slug to set
     */
    public void setSlug(String slug) {
        this.slug = slug;
    }

    public String getName() {
        return name;
    }

    /**
     * @param name 
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 
     * @return
     */
    public Point getNewPoint() {
        return new Point();
    }

    /**
     * @return the activity
     */
    public String getActivity() {
        return activity;
    }

    /**
     * @param activity the activity to set
     */
    public void setActivity(String activity) {
        this.activity = activity;
    }

    /**
     * @return the startpoint
     */
    public Point getStartpoint() {
        return startpoint;
    }

    /**
     * @param startpoint the startpoint to set
     */
    public void setStartpoint(Point startpoint) {
        this.startpoint = startpoint;
    }

    /**
     * @return the hardware
     */
    public String getHardware() {
        return hardware;
    }


    /**
     * @return the publicview
     */
    public Boolean getPublicview() {
        return publicview;
    }

    public Boolean isPublicview() {
        return publicview;
    }

    /**
     * @param publicview the publicview to set
     */
    public void setPublicview(Boolean publicview) {
        this.publicview = publicview;
    }

    /**
     * @return the tags
     */
    public String getTags() {
        return tags;
    }

    /**
     * @param tags the tags to set
     */
    public void setTags(String tags) {
        this.tags = tags;
    }

    /**
     * @return the tagsLink
     */
    public List<Tag> getTagsLink() {
        return tagsLink;
    }

    /**
     * @param tagsLink the tagsLink to set
     */
    public void setTagsLink(List<Tag> tagsLink) {
            if (this.tagsLink == null || this.tagsLink.isEmpty()) {
            this.tagsLink = new ArrayList<Tag>();
        }    
        
        this.tagsLink = tagsLink;
    }

    /**
     * @param tag 
     */
    public void addTagLink(Tag tag) {
        
        if (this.tagsLink == null || this.tagsLink.isEmpty()) {
            this.tagsLink = new ArrayList<Tag>();
        }

        this.tagsLink.add(tag);
    }

    /**
     * @return the totDistance
     */
    public Double getTime() {

        double tot = 0;

        return tot;

    }

    /**
     * @return the totDislivello
     */
    public Double getDislivello() {
        if (maxAltitude != 0 && minAltitude != 0) {
            return Math.abs(maxAltitude - minAltitude);
        }

        return (double) 0;

    }

    /**
     * 
     * @return
     */
    public List<Media> getMedia() {
        return media;

    }

    /**
     * 
     * @param media
     */
    public void addMedia(Media media) {

        if (this.media == null) {
            this.setMedia(new ArrayList<Media>());
        }

        this.media.add(media);
    }

    /**
     * 
     * @param media
     */
    public void setMedia(List<Media> media) {
        this.media = media;
    }

    /**
     * @return the distance
     */
    public Double getDistance() {
        return distance;
    }

    /**
     * @param distance the distance to set
     */
    public void setDistance(Double distance) {
        this.distance = distance;
    }

    /**
     * @return the dateSaved
     */
    public Date getDateSaved() {
        return dateSaved;
    }

    /**
     * @param dateSaved the dateSaved to set
     */
    public void setDateSaved(Date dateSaved) {
        this.dateSaved = dateSaved;
    }

    /**
     * @return the datestart
     */
    public Date getDatestart() {
        return datestart;
    }

    /**
     * @param datestart the datestart to set
     */
    public void setDatestart(Date datestart) {
        this.datestart = datestart;
    }

    /**
     * @return the datestop
     */
    public Date getDatestop() {
        return datestop;
    }

    /**
     * @param datestop the datestop to set
     */
    public void setDatestop(Date datestop) {
        this.datestop = datestop;
    }

    /**
     * @return the trackpoint
     */
    public TrackPoint getTrackpoint() {
        return trackpoint;
    }

    /**
     * @param trackpoint the trackpoint to set
     */
    public void setTrackpoint(TrackPoint trackpoint) {
        this.trackpoint = trackpoint;
    }

    /**
     * @return the elevation
     */
    public Double getElevation() {
        return elevation;
    }

    /**
     * @param elevation the elevation to set
     */
    public void setElevation(Double elevation) {
        this.elevation = elevation;
    }

    /**
     * @return the realelevation
     */
    public Double getRealelevation() {
        return realelevation;
    }

    /**
     * @param realelevation the realelevation to set
     */
    public void setRealelevation(Double realelevation) {
        this.realelevation = realelevation;
    }

    /**
     * @return the fileImported
     */
    public File getFileImported() {
        return fileImported;
    }

    /**
     * @param fileImported the fileImported to set
     */
    public void setFileImported(File fileImported) {
        this.fileImported = fileImported;
    }




    /**
     * @param hardware the hardware to set
     */
    public void setHardware(String hardware) {
        this.hardware = hardware;
    }

    /**
     * @return the hardwareLink
     */
    public Hardware getHardwareLink() {
        return hardwareLink;
    }

    /**
     * 
     * @param hardwarelink
     */
    public void setHardwareLink(Hardware hardwarelink) {
        this.hardwareLink = hardwarelink;
    }
}
